package com.hl.sfzy.controller;

import com.github.pagehelper.PageInfo;
import com.hl.sfzy.entity.Usermark;
import com.hl.sfzy.service.UserMarkService;
import com.hl.sfzy.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/usermark")
@CrossOrigin
public class UserMarkController {
    @Autowired
    private UserMarkService userMarkService;
    @DeleteMapping("/{id}")
    public R remove(@PathVariable Long id){
        int i = userMarkService.remove(id);
        if(i>0){
            return R.ok("删除成功");
        }
        return R.error("删除失败");
    }
    @PostMapping ("/add")
    public R add(@RequestBody Usermark usermark){
        int i = userMarkService.add(usermark);
        if(i>0){
            return R.ok("添加成功");
        }
        return R.error("添加失败");
    }
    @PutMapping("/edit")
    public R edit(@RequestBody Usermark usermark){
        int i = userMarkService.edit(usermark);
        if(i>0){
            return R.ok("修改成功");
        }
        return R.error("修改失败");
    }
    @GetMapping("/{id}")
    public R findById(@PathVariable Long id){
        Usermark usermark = userMarkService.findById(id);
        if(usermark!=null){
            return R.ok(usermark);
        }
        return R.error("查询失败");
    }
    @GetMapping("/findAll")
    public R findAll(
            @RequestParam(required = false,defaultValue = "1") int pageNum,
            @RequestParam(required = false,defaultValue = "5") int pageSize,
            Usermark usermark
            ){
        PageInfo<Usermark> pageInfo = userMarkService.findAll(pageNum, pageSize, usermark);
        return R.ok(pageInfo);
    }
    @GetMapping("/findByConsultId")
    public R findByConsultId(Integer id){
        return R.ok(userMarkService.findByConsultId(id));
    }
}
